package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/4/2 11:19
 * @description
 */
public class Code15 {
    public List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        int pre = Integer.MAX_VALUE;
        List<List<Integer>> lists = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            int n1 = nums[i];
            if (pre == n1) {
                continue;
            }
            for (int j = i + 1; j < nums.length; j++) {
                for (int k = j + 1; k < nums.length; k++) {
                    if (n1 + nums[j] + nums[k] == 0) {
                        lists.add(Arrays.asList(n1, nums[j], nums[k]));
                        break;
                    }
                }
            }
            pre = n1;
        }
        return lists;
    }
}
